package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.apis.admin.AdChannelControllerApi;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController implements AdChannelControllerApi {

    /**
     * @Description: 频道列表
     * @Author: 熊佳杰
     * @Date: 2021/1/28
     */
    @Autowired
    private AdChannelService adChannelService;

    @PostMapping("/list")
    @Override
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return adChannelService.findByNameAndPage(dto);
    }

    /**
     * @Description: 频道新增
     * @Author: 熊佳杰
     * @Date: 2021/1/28
     */
    @PostMapping("save")
    @Override
    public ResponseResult save(@RequestBody AdChannel channel) {
        ResponseResult responseResult = adChannelService.insert(channel);
        return responseResult;
    }

    /**
     * @Description: 频道修改
     * @Author: 熊佳杰
     * @Date: 2021/1/28
     */
    @PostMapping("update")
    @Override
    public ResponseResult update(@RequestBody AdChannel adChannel) {

        return adChannelService.update(adChannel);
    }

    /**
     * @Description: 频道删除
     * @Author: 熊佳杰
     * @Date: 2021/1/28
     */
    @GetMapping("del/{id}")
    @Override
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return adChannelService.deleteById(id);
    }

    @GetMapping("/channels")
    @Override
    public ResponseResult findAll() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }
}
